<%@include file="../common.jsp" %>
<script type="text/javascript">
$(document).ready(
		function() {
			$("#saveCompanyDetails").attr("action",'<c:url value="/saveCompanyNewDetails.htm"></c:url>');
			enableDisableSelectCompany('id');
			loadBelowValues('state','district');
			$("#editCompanyDiv").css("display","none");
		});
</script>

<div>
	<c:choose>
		<c:when test="${fn:length(companyMap) > 0}">
			<form name="editCompany" id="editCompany">
				<div style="width: 70%;">
					<table class="viewDetails" id="selectCompanyTable">
						<tr class="adminTableMainHeaderColor tableChildHeaderFont">
							<th colspan="9" align="center"><span class="searchResultsCaption" >EDIT COMPANIES</span></th>
						</tr>
						
						<tr class="heading">
							<th>Select</th>
							<th>Name</th>
							<th>Type</th>
							<th>Code</th>
							<th>Company Address</th>
						</tr>	
					
						<c:forEach items="${companyMap}" var="companyMap" varStatus="loop">
						
							<c:set var="tabColor" value="odd"></c:set>
					     	<c:if test="${(loop.index % 2) eq 0}">
					        	<c:set var="tabColor" value="even"></c:set>
					        </c:if>
					    <tr class="${tabColor}">
					    	<td align="center"> 
					    		<input type="radio" id="radio${loop.index}" 
					    			name="radio" 
					    			value="${companyMap.value.cdId},${companyMap.value.cdName},
					    				${companyMap.value.cdCode},${companyMap.value.address},
					    				${companyMap.value.cdCity},${companyMap.value.cdDistrict},
					    				${companyMap.value.cdState},${companyMap.value.child},
					    				${companyMap.value.parentId},${companyMap.value.companyType}" onclick="enableSelectButton('companySelectButton');"/> 
					    	</td>
							<td> ${companyMap.value.cdName} </td>
							<td> <c:if test="${fn:contains(companyMap.value.companyType,'GroupHead')}">Group company</c:if>
						 		 <c:if test="${fn:contains(companyMap.value.companyType,'StandAlone')}">Stand Alone company</c:if>
								 <c:if test="${fn:contains(companyMap.value.companyType,'Subsidiary')}">Subsidiary company</c:if> </td>
							<td> ${companyMap.value.cdCode} </td>
							<td> ${companyMap.value.address} ${companyMap.value.cdCity}  ${companyMap.value.cdDistrict}  ${companyMap.value.cdState} </td>
						</tr>	
						</c:forEach>
					</table>
					<table>
						<tr align="left">
							<td colspan="5">
								<input class="formButton ui-corner-all" type="button" 
									id="companySelectButton" disabled="true" value="SELECT" style="opacity:6; filter:alpha(opacity=60);" onclick="submitCompanyDetailsToEdit();" />
							</td>
						</tr>
					</table>
				</div>
			</form>
		
			
				<c:if test="${resultOfSave}">
					Operation Done Successfully.
				</c:if>
				
					<br>
					<hr style="height: 4px; background-color: black;"/>
					<br>

				<div id="editCompanyDiv">
					<form:form commandName="companyDetailsDTO" name="saveCompanyDetails" id="saveCompanyDetails">
						<table class="adminFilterTable">
							<tr class="tableChildHeaderColor"> 
								<th colspan="4"> EDIT DETAILS FOR COMPANY </th> 
							</tr>
							 <form:hidden path="cdId" id="companyId"></form:hidden> 
							<tr class="formSpacingRow"><td></td> </tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr>
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel"> Type* </td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">
									<table>
										<tr align="left">
											<td><form:input path="companyType" type="radio"
													id="groupCompany" name="companySetup" value="GroupHead"
													onclick="enableDisableSelectCompany('groupCompany');" />Group
												Head Company</td>
										</tr>
										<tr align="left">
											<td><c:if test="${!(fn:length(parentCompaniesList) eq 0)}">
													<form:input path="companyType" type="radio"
														id="subsidiaryCompany" name="companySetup"
														value="Subsidiary"
														onclick="enableDisableSelectCompany('subsidiaryCompany');" />Subsidiary Company
											
													<form:select id="parentId" path="parentId" cssClass="disableInputField">
														<c:forEach items="${parentCompaniesList}"
															var="parentCompany">
															<form:option value="${parentCompany.cdId}">${parentCompany.cdName}</form:option>
														</c:forEach>
													</form:select>
												</c:if></td>
										</tr>
										<tr align="left">
											<td><form:input path="companyType" type="radio"
													id="standAloneCompany" name="companySetup" value="StandAlone"
													onclick="enableDisableSelectCompany('standAloneCompany');" />Stand
												Alone Company</td>
										</tr>
									</table> 
									<form:errors path="companyType" cssClass="errorMsg" />
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr> 
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">Name*</td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formField"><form:input path="cdName" id="companyName"></form:input>
										<label class="formLabel"><form:errors cssClass="errorMessage" path="cdName"></form:errors></label> 
										
								</td>	
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr> 
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">Code*</td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formField"><form:input path="cdCode" id="companyCode"  readonly="true"></form:input> 
										<label class="formLabel"><form:errors cssClass="errorMessage" path="cdCode"></form:errors></label>
								</td>
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr> 
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">Address</td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formField"><form:input path="address" id="companyAddress"></form:input>
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr> 
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">State</td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formField"><form:select path="cdState" id="state"
										onchange="loadBelowValues(this.id,'district');">
										<form:option value="">Choose State</form:option>
										<c:forEach var="stateSet" items="${stateSet}">
											<form:option value="${stateSet}">${stateSet}</form:option>
										</c:forEach>
									</form:select></td>
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr>
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">District</td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formField"><form:select path="cdDistrict" id="district"
										onchange="loadBelowValues(this.id,'city');"></form:select></td>
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr> 
								<td class="spacingColumnWidthLess"></td>
								<td class="formLabel">City</td>
								<td class="spacingColumnWidthLess"></td>
								<td class="formField"><form:select path="cdCity" id="city"></form:select></td>
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
							<tr class="even" align="center">
								<td class="spacingColumnWidthLess"></td>
								<td></td>
								<td class="spacingColumnWidthLess"></td>
								<td align="left">
										<input class="formButton ui-corner-all" type="button" value="UPDATE" onclick="javascript:addEntity('saveCompanyDetails')">
								</td>
							</tr>
							<tr class="formSpacingRow"><td></td> </tr>
						</table>
					</form:form>
				</div>
				</c:when>
		<c:otherwise>
			<label class="formLabel" style="font-weight: bold;">No Records Found.</label>
		</c:otherwise>
	</c:choose>
</div>
